package com.chenjj.bigdata.hive.util;

import org.junit.Test;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

public class DBUtilTester {

    /**
     * 测试impala
     */
    @Test
    public  void test1() throws ClassNotFoundException {
//        String url = "jdbc:impala://192.168.152.146:21050/hdm;AuthMech=3;PreparedMetaLimitZero=0;";
//        String user = "etluser";
//        String password = "123456";
//        String driver = "com.cloudera.impala.jdbc41.Driver";
//        Connection connection = DBUtil.getConnection(url,user,password,driver);
//        if (null != connection){
//            List<Map<String,Object>> result =  DBUtil.executeQuery(connection,"select * from hdm.h_trade_info");
//            for (Map row: result
//                 ) {
//                System.out.println(row.get("pay_tpye"));
//            }
//        }

        String url = "jdbc:impala://10.22.82.103:21050/default;AuthMech=3";
        String user = "edwuser";
        String password = "edwuser";
        String driver = "com.cloudera.impala.jdbc41.Driver";
        Connection connection = DBUtil.getConnection(url,user,password,driver);
        if (null != connection){
            List<Map<String,Object>> result =  DBUtil.executeQuery(connection,"show databases");
            for (Map row: result
                 ) {
                System.out.println(row);
            }
        }

    }

    /**
     * 测试hive高可用链接
     */
    @Test
    public void test2() throws ClassNotFoundException {
        String url = "jdbc:hive2://node1:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2_zk";
        String user = "etluser";
        String password = "123456";
        String driver = "org.apache.hive.jdbc.HiveDriver";
        Connection connection = DBUtil.getConnection(url,user,password,driver);
        if (null != connection){
            List<Map<String,Object>> result =  DBUtil.executeQuery(connection,"select * from hdm.h_trade_info");
            for (Map row: result
            ) {
                System.out.println(row.get("h_trade_info.pay_tpye"));
            }
        }
    }
}
